<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="DecisionMaking.Domain" %>
<%@ Import Namespace="DecisionMaking.WebApp" %>
<%@ Import Namespace="MvcContrib.UI.Grid" %>
<%@ Import Namespace="MvcContrib.UI.MenuBuilder" %>

<asp:Content ContentPlaceHolderID="TitleContent" runat="server">Manage Cues</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MenuContent" runat="server">
    <% Html.Menu(Navigation.MainMenu(Url, ((DecisionMaking.Domain.Environment)ViewData["environment"]).Id)); %>
</asp:Content>

<asp:Content ContentPlaceHolderID="MainContent" runat="server">
	<script type="text/javascript">
        function update(context) {
            // Load and deserialize the returned JSON data
            var json = context.get_data();
            var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);
 
            // delete the row from the grid
			$('#cue-' + data.deletedId).fadeOut();
        }		
	</script>

	<p>
		<%= Html.ActionLink("New Cue", "Add", new {Id = ((DecisionMaking.Domain.Environment)ViewData["environment"]).Id}, null) %>
	</p>
	<% Html.Grid<Cue>("cues").Columns( column => {
		column.For(c => c.Name);
        column.For(c => c.SortOrder).Named("Order");
        foreach (var a in (IEnumerable<CueAttribute>)ViewData["cueAttributes"])
		{
		    var attr = a; // we have to copy the attribute into the closure, otherwise only the last value is used in all closure instances
		    column.For(c => c.GetAttributeValue(attr)).Named(attr.Name);
		}
        column.For(c => Html.ActionLink("Edit", "Edit", new { id = c.Id })).DoNotEncode();        
        column.For(c => Ajax.ActionLink("Remove", "Delete", new {id = c.Id}, new AjaxOptions{OnSuccess = "update"})).DoNotEncode();
	})
	.RowAttributes(row => new Dictionary<string, object>{{"id", "cue-" + row.Item.Id}})
	.Render();
	%>
	
	<p>
		<%= Html.ActionLink("Next", "List", "Candidates", new { Id = ((DecisionMaking.Domain.Environment)ViewData["environment"]).Id }, null)%>
	</p>      	
</asp:Content>

